#include <unordered_set>
#include <vector>
using namespace std;
int candy(vector<int> &ratings) {
  int n = ratings.size();
  vector<int> candy(n, 1);
  // 考虑 左边大于右边的情况
  for (int i = 1; i < n; ++i) {
    if (ratings[i] > ratings[i - 1]) {
      candy[i] = candy[i - 1] + 1;
    } else {
      candy[i] = 1;
    }
  }
  candy[n - 1] = max(1, candy[n - 1]);
  // 考虑右边大于左边的情况
  for (int i = n - 2; i >= 0; --i) {
    if (ratings[i] > ratings[i + 1]) {
      candy[i] = max(candy[i], candy[i + 1] + 1);
    } else {
      candy[i] = max(candy[i], 1);
    }
  }
  int count = 0;
  for (int i : candy) {
    count += i;
  }
  return count;
}